/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.common.query.expression;

import java.util.Collection;

import com.eelpo.common.query.criteria.Criteria;

/**
 * <pre>
 * 
 * Exists表达试
 * 
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class ExistsExpression implements ParameterCriterion {

	private String operator;
	private Criteria criteria;

	private ExistsExpression(String operator, Criteria criteria) {
		this.operator = operator;
		this.criteria = criteria;
	}

	public static ExistsExpression getExistsExpression(Criteria criteria) {
		return new ExistsExpression(EXISTS, criteria);
	}

	public static ExistsExpression getNotExistsExpression(Criteria criteria) {
		return new ExistsExpression(NOTEXISTS, criteria);
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.common.query.expression.ParameterCriterion#getJpql(java.lang.
	 *      StringBuilder)
	 */
	@Override
	public StringBuilder getJpql(StringBuilder jpql, String ailas) {
		jpql.append(AND);
		jpql.append(operator);
		jpql.append("(");
		criteria.getJpql(jpql);
		jpql.append(")");
		return jpql;
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.common.query.expression.ParameterCriterion#getParameters(java.util.
	 *      Collection)
	 */
	@Override
	public Collection<Object> getParameters(Collection<Object> parameters) {
		criteria.getParameters(parameters);
		return parameters;
	}

}
